﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.Config
{
	// Token: 0x02000330 RID: 816
	public class QAOnlineSettings : Singleton<QAOnlineSettings>
	{
		// Token: 0x17000398 RID: 920
		// (get) Token: 0x060012F9 RID: 4857 RVA: 0x00008EC3 File Offset: 0x000070C3
		public string[] RuleIdList
		{
			get
			{
				return Enumerable.ToArray<string>(this.qaSettings.ruleDataDic.Keys);
			}
		}

		// Token: 0x17000399 RID: 921
		// (get) Token: 0x060012FA RID: 4858 RVA: 0x0005B378 File Offset: 0x00059578
		private Dictionary<string, QAOnlineSettings.RuleData> ruleDataDictionary
		{
			get
			{
				return this.qaSettings.ruleDataDic;
			}
		}

		// Token: 0x1700039A RID: 922
		// (get) Token: 0x060012FB RID: 4859 RVA: 0x00008EDA File Offset: 0x000070DA
		public List<ScanAssetsConfig> IgnoreDirList
		{
			get
			{
				return this.qaSettings.ignoreDirList;
			}
		}

		// Token: 0x060012FC RID: 4860 RVA: 0x00008EE7 File Offset: 0x000070E7
		public QAOnlineSettings()
		{
			this.LoadSettings();
		}

		// Token: 0x060012FD RID: 4861 RVA: 0x0005B398 File Offset: 0x00059598
		private void LoadSettings()
		{
			string path = Path.Combine(Application.dataPath, "..", "QAOnlineSettings.json");
			bool flag = File.Exists(path);
			if (flag)
			{
				string text = File.ReadAllText(path);
				this.qaSettings = JsonConvert.DeserializeObject<QAOnlineSettings.QASettings>(text);
			}
			else
			{
				this.qaSettings = new QAOnlineSettings.QASettings();
				ScanLog.UnityLog("QAOnlineSettings.json文件不存在，使用默认设置。");
			}
		}

		// Token: 0x060012FE RID: 4862 RVA: 0x0005B3F4 File Offset: 0x000595F4
		public bool? GetCheckEnabled(string ruleId)
		{
			QAOnlineSettings.RuleData ruleData;
			return this.ruleDataDictionary.TryGetValue(ruleId, out ruleData) ? ruleData.CheckEnabled : null;
		}

		// Token: 0x060012FF RID: 4863 RVA: 0x0005B428 File Offset: 0x00059628
		public float GetThresholds(string ruleId)
		{
			QAOnlineSettings.RuleData ruleData;
			return (float)(this.ruleDataDictionary.TryGetValue(ruleId, out ruleData) ? (ruleData.Thresholds ?? -1) : -1);
		}

		// Token: 0x06001300 RID: 4864 RVA: 0x0005B468 File Offset: 0x00059668
		public List<string> GetWhiteList(string ruleId)
		{
			QAOnlineSettings.RuleData ruleData;
			return this.ruleDataDictionary.TryGetValue(ruleId, out ruleData) ? ruleData.WhiteList : null;
		}

		// Token: 0x04000B62 RID: 2914
		private const string SettingsFileName = "QAOnlineSettings.json";

		// Token: 0x04000B63 RID: 2915
		private QAOnlineSettings.QASettings qaSettings;

		// Token: 0x02000331 RID: 817
		private class QASettings
		{
			// Token: 0x04000B64 RID: 2916
			[JsonProperty("Rule_Config")]
			public Dictionary<string, QAOnlineSettings.RuleData> ruleDataDic = new Dictionary<string, QAOnlineSettings.RuleData>();

			// Token: 0x04000B65 RID: 2917
			[JsonProperty("Global_Ignore_Config")]
			public List<ScanAssetsConfig> ignoreDirList = new List<ScanAssetsConfig>();
		}

		// Token: 0x02000332 RID: 818
		private class RuleData
		{
			// Token: 0x04000B66 RID: 2918
			public bool? CheckEnabled;

			// Token: 0x04000B67 RID: 2919
			public int? Thresholds;

			// Token: 0x04000B68 RID: 2920
			public List<string> WhiteList;
		}
	}
}
